package com.heart.edu.web.controller.base;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public abstract class BaseController<T> {

    public static String MANAGE_PAGE;//管理页面
    public static String INFO_PAGE;//列表页面
    public static String EDIT_PAGE;//编辑页面


    public static final String MANAGE = "manage";//管理
    public static final String INFO = "info";//列表
    public static final String EDIT= "edit";//编辑

    public BaseController(){
        //1.获取泛型的真实类型
        ParameterizedType type = (ParameterizedType) this.getClass().getGenericSuperclass();
        System.out.println("=====" + type);
    //=====com.yuxiu.edu.web.controller.base.BaseController<com.yuxiu.edu.model.User>
        Class<?> modelClass = (Class<?>) type.getActualTypeArguments()[0];
        System.out.println("=====" +  modelClass);

        //2.获取模块名
        String moduleName = modelClass.getSimpleName().toLowerCase();


        //3.给静态页面赋值
        MANAGE_PAGE = moduleName + "/" + MANAGE;
        INFO_PAGE = moduleName + "/" + INFO;
        EDIT_PAGE = moduleName + "/" + EDIT;
    }
}